package com.zzj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzj.bean.TeamBean;
import com.zzj.dao.TeamDao;
import com.zzj.service.TeamService;
import com.zzj.utils.Result;
import com.zzj.utils.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service
public class TeamServiceImpl implements TeamService {
    @Autowired
    private TeamDao teamDao;

    /**
     * 向team表中添加一行数据
     * @param teamBean
     * @return
     */
    @Override
    public Result addTeam(TeamBean teamBean) {
        int i = teamDao.addTeam(teamBean);
        if (i==1){
            return new Result(true, StatusCode.OK,"添加成功");
        }
        return new Result(false,StatusCode.ERROR,"添加失败");
    }

    /**
     * 通过ID修改team表中的信息
     * @param teamBean
     * @return
     */
    @Override
    public Result updTeam(TeamBean teamBean) {
        int i = teamDao.updTeam(teamBean);
        if (i==1){
            return new Result(true,StatusCode.OK,"修改成功");
        }
        return new Result(false,StatusCode.ERROR,"添加失败");
    }

    /**
     * 通过ID删除team表中的数据
     * @param tid
     * @return
     */
    @Override
    public Result delTeamByTid(int tid) {
        int i = teamDao.delTeamByTid(tid);
        if (i==1){
            return new Result(true,StatusCode.OK,"删除成功");
        }
        return new Result(false,StatusCode.ERROR,"添加失败");
    }

    /**
     * 查看team表中的所有信息
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Result<PageInfo<TeamBean>> findAll(Integer pageNum, Integer pageSize) {
        List<TeamBean> all = teamDao.findAll(pageNum, pageSize);
        if (all!=null){
            PageHelper.startPage(pageNum, pageSize);
            PageInfo<TeamBean> allTeam = new PageInfo<>(all);
            return new Result<>(true,StatusCode.OK,"查询成功",allTeam);
        }
        return new Result<>(false,StatusCode.ERROR,"列表为空");
    }

    /**
     * 通过部门ID查询team表中的一行信息
     * @param did
     * @return
     */
    @Override
    public Result findTeamByDid(int did) {
        List<TeamBean> teamByDid = teamDao.findTeamByDid(did);
        if (teamByDid!=null){
            return new Result(true,StatusCode.OK,"查询成功",teamByDid);
        }
        return new Result(false,StatusCode.ERROR,"列表为空");
    }
    public Result findTeamByTid(int tid){
        TeamBean teamByTid = teamDao.findTeamByTid(tid);
        if (teamByTid!=null){
            return new Result(true,StatusCode.OK,"查询成功",teamByTid);
        }
        return new Result(false,StatusCode.ERROR,"列表为空");
    }
}
